/*
 * Copyright (c) Huawei Device Co., Ltd. 2023. All rights reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#include "apdu_validator.h"

#include <gtest/gtest.h>
#include <memory>

#include "common_utils.h"
#include "loghelper.h"
#include "se_common_exception.h"
#include "application_parser.h"
#include "sha256_utils.h"
#include "se_hisysevent.h"

namespace OHOS {
namespace SE {
namespace TEST {
using namespace testing::ext;
using namespace OHOS::SE;

class ApduValidatorTest : public testing::Test {
public:
    static void SetUpTestCase() {};
    static void TearDownTestCase() {};
    void SetUp() {};
    void TearDown() {};
public:
    std::shared_ptr<ApduValidator> apduValidator = std::make_shared<ApduValidator>();
};

/**
 * @tc.name: CheckCommand_Test001
 * @tc.desc: Test CheckCommand.
 * @tc.type: FUNC
 */
HWTEST_F(ApduValidatorTest, CheckCommand_Test001, TestSize.Level1)
{
    try {
        apduValidator->CheckCommand("12");
        EXPECT_TRUE(apduValidator != nullptr);
    } catch (const IllegalArgumentError &e) {
        ErrorLog("exception happens.");
    }
}

/**
 * @tc.name: CheckCommand_Test003
 * @tc.desc: Test CheckCommand.
 * @tc.type: FUNC
 */
HWTEST_F(ApduValidatorTest, CheckCommand_Test003, TestSize.Level1)
{
    try {
        apduValidator->CheckCommand("FF23456789");
        EXPECT_TRUE(apduValidator != nullptr);
    } catch (const IllegalArgumentError &e) {
        ErrorLog("exception happens.");
    }
}

/**
 * @tc.name: CheckCommand_Test004
 * @tc.desc: Test CheckCommand.
 * @tc.type: FUNC
 */
HWTEST_F(ApduValidatorTest, CheckCommand_Test004, TestSize.Level1)
{
    try {
        apduValidator->CheckCommand("0160456789");
        EXPECT_TRUE(apduValidator != nullptr);
    } catch (const IllegalArgumentError &e) {
        ErrorLog("exception happens.");
    }
}

/**
 * @tc.name: CheckCommand_Test005
 * @tc.desc: Test CheckCommand.
 * @tc.type: FUNC
 */
HWTEST_F(ApduValidatorTest, CheckCommand_Test005, TestSize.Level1)
{
    try {
        apduValidator->CheckCommand("0190456789");
        EXPECT_TRUE(apduValidator != nullptr);
    } catch (const IllegalArgumentError &e) {
        ErrorLog("exception happens.");
    }
}

/**
 * @tc.name: CheckCommand_Test006
 * @tc.desc: Test CheckCommand.
 * @tc.type: FUNC
 */
HWTEST_F(ApduValidatorTest, CheckCommand_Test006, TestSize.Level1)
{
    try {
        apduValidator->CheckCommand("0123456700AB");
        EXPECT_TRUE(apduValidator != nullptr);
    } catch (const IllegalArgumentError &e) {
        ErrorLog("exception happens.");
    }
}

/**
 * @tc.name: CheckCommand_Test007
 * @tc.desc: Test CheckCommand.
 * @tc.type: FUNC
 */
HWTEST_F(ApduValidatorTest, CheckCommand_Test007, TestSize.Level1)
{
    apduValidator->CheckCommand("0123456701AB");
    EXPECT_TRUE(apduValidator != nullptr);
}

/**
 * @tc.name: CheckCommand_Test008
 * @tc.desc: Test CheckCommand.
 * @tc.type: FUNC
 */
HWTEST_F(ApduValidatorTest, CheckCommand_Test008, TestSize.Level1)
{
    apduValidator->CheckCommand("0123456701AB11");
    EXPECT_TRUE(apduValidator != nullptr);
}

/**
 * @tc.name: CheckCommand_Test009
 * @tc.desc: Test CheckCommand.
 * @tc.type: FUNC
 */
HWTEST_F(ApduValidatorTest, CheckCommand_Test009, TestSize.Level1)
{
    try {
        apduValidator->CheckCommand("0123456701AB1111");
        EXPECT_TRUE(apduValidator != nullptr);
    } catch (const IllegalArgumentError &e) {
        ErrorLog("exception happens.");
    }
}

/**
 * @tc.name: IsSystemApplication_Test001
 * @tc.desc: Test IsSystemApplication.
 * @tc.type: FUNC
 */
HWTEST_F(ApduValidatorTest, IsSystemApplication_Test001, TestSize.Level1)
{
    std::shared_ptr<ApplicationParser> applicationParser = std::make_shared<ApplicationParser>();
    applicationParser->IsSystemApplication(123);
    EXPECT_TRUE(applicationParser != nullptr);
}

/**
 * @tc.name: CalculateHashCode_Test001
 * @tc.desc: Test CalculateHashCode.
 * @tc.type: FUNC
 */
HWTEST_F(ApduValidatorTest, CalculateHashCode_Test001, TestSize.Level1)
{
    std::shared_ptr<Sha256Utils> sha256Utils = std::make_shared<Sha256Utils>();
    sha256Utils->CalculateHashCode("");
    EXPECT_TRUE(sha256Utils != nullptr);
}

/**
 * @tc.name: WriteSeResponseHiSysEvent_Test001
 * @tc.desc: Test WriteSeResponseHiSysEvent.
 * @tc.type: FUNC
 */
HWTEST_F(ApduValidatorTest, WriteSeResponseHiSysEvent_Test001, TestSize.Level1)
{
    std::shared_ptr<SeHisysEvent> event = std::make_shared<SeHisysEvent>();
    event->WriteSeResponseHiSysEvent("", "12");
    EXPECT_TRUE(event != nullptr);
}
} // TEST
} // SE
} // OHOS